package com.guigu.serviceorder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.common_util.pojo.utils.Result;
import com.guigu.serviceorder.entity.TbCategoryReport;
import com.guigu.serviceorder.mapper.TbCategoryReportMapper;
import com.guigu.serviceorder.service.ITbCategoryReportService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2020-07-08
 */
@Service
public class TbCategoryReportServiceImpl extends ServiceImpl<TbCategoryReportMapper, TbCategoryReport> implements ITbCategoryReportService {



    @Override
    public Result findPage(Map<String, Object> searchMap, Integer page, Integer size) {
        QueryWrapper<TbCategoryReport> wrapper = createExample(searchMap);
        //创建page对象
        Page<TbCategoryReport> pageTbCategoryReport = new Page<>(page,size);
        baseMapper.selectPage(pageTbCategoryReport,wrapper);
        if (pageTbCategoryReport.getRecords() == null && pageTbCategoryReport.getTotal() == 0){
            return Result.error();
        }
        return Result.ok().data("rows",pageTbCategoryReport.getRecords()).data("total",pageTbCategoryReport.getTotal());
    }

    // 根据查询条件封装模块对象
    private QueryWrapper<TbCategoryReport> createExample(Map<String, Object> searchMap) {
        QueryWrapper<TbCategoryReport> wrapper = new QueryWrapper<>();
        if(searchMap!=null) {
            if(searchMap.get("id")!=null)
                wrapper.eq("id",searchMap.get("id"));
        }
        return wrapper;
    }
}
